<?php
session_start(); 
if(!isset($_SESSION['userName'])){
header( 'location: ../index.php' ); 
}

include("../conf/connect.php");
	$user_id = $_SESSION['user_id'];
	$qus_no = $_GET['qus'];
	$hid = $_SESSION['usrHHid'];
	
	$lastdata = mysql_query("select id from lastid where user_id='$user_id' and hid ='$hid' order by id desc");
	$linkarray = mysql_fetch_array($lastdata);
	$lastinid = $linkarray['id'];
	$_SESSION['lid']=$lastinid;
	$resId =$lastinid;
	

  if($qus_no =='loc'){
    $loc = $_POST['loc'];
	$vil = $_POST['vil'];
	$_SESSION['usrLoc']=$loc.$vil;
	header( "location: ../index1.php" );
  }  
  else if($qus_no =='hid'){
  	$hid = $_POST["data"]["f"] .$_POST["data"]["s"] .$_POST["data"]["t"] ;
	if($hid=='000'){
		header( "location: hid.php");
	}
	else{
		$_SESSION['usrHHid']= $_SESSION['usrLoc'].$hid;
		$checkhid = $_SESSION['usrHHid'];
		$sql = "SELECT id FROM raw_data  WHERE hid ='$checkhid'";
		$result=mysql_query( $sql);
		$row = mysql_fetch_array($result);
		//print_r($row);
			if(empty ($row)){
				//echo "uuu";
				header( "location: qus1.php?serial=1" );
			}
			else{
				$_SESSION['error']= "this HH is Exist !!!";
				header( "location: hid.php");
			}
	}
  } 
  else if($qus_no ==1){
		$time = date('Y-m-d H:i:s',strtotime("+10 hours"));
//		$explode = explode("-",$time);

	$name = $_POST["data"]["name"];
	$completed_id = $_POST['completed_id'];
	$_SESSION['completed_id']=$completed_id;
	$completed = $_POST['completed'];
	if($name==''){
		header( "location: qus1.php?serial=1" );
	}
	else{
		if($completed=='0'){
			$sql="UPDATE raw_data set q1='$name' WHERE id='$completed_id'";
			mysql_query($sql) or die ("problem on updating household");	
			$lidinsert= mysql_insert_id();
			$_SESSION['lid']=$lidinsert;				
			header( "location: qus1.php?serial=2" );		
		}
		else{
			$sql="INSERT INTO raw_data (id, rid, user_id, hid, q1, q2, q3, q4, q5, q6, q7, q8, is_delete, status) VALUES ('', '1', '$user_id','$hid','$name', '00', '0', '0', '0', '00', '00', '0', 0, 0)";
			mysql_query($sql) or die ("problem insert household");
			//q2='$age', q3='$sex', q4='$mStatus', q5='$relation', q6='$schooling', q7='$occupation', q8='$sType',
			$lidinsert= mysql_insert_id();
			$_SESSION['lid']=$lidinsert;
			$_SESSION['completed_id']=$lidinsert;
			$hcsql="INSERT INTO elapsed_time (id, user_id, hhid, start_time, is_delete, status) VALUES ('', '$user_id', '$hid','$time', 0, 0)";
			mysql_query($hcsql) or die ("problem timing");
			$hcsql="INSERT INTO household_info (id, hid, is_delete, status) VALUES ('', '$hid', 0, 0)";
			mysql_query($hcsql) or die ("problem household condition");
			$ecosql="INSERT INTO household_economic (id, hid, is_delete, status) VALUES ('', '$hid', 0, 0)";
			mysql_query($ecosql) or die ("problem household economy");
			$astsql="INSERT INTO household_asset (id, hid, is_delete, status) VALUES ('', '$hid', 0, 0)";
			mysql_query($astsql) or die ("problem household asset");
			
			$sql="INSERT INTO track (id, user_id, hid, appid, qid, is_delete, status) VALUES ('', '$user_id','$hid','$lidinsert', '1', 0, 1)";
			mysql_query($sql) or die ("problem budget_heads");
			$sql="INSERT INTO lastid (id,user_id,hid,status) VALUES ('$lidinsert',$user_id,$hid,0)";
			mysql_query($sql) or die ("problem budget_heads");				
			header( "location: qus1.php?serial=2" );
		}
	}
	
  }
  
  else if($qus_no =='2'){
	
	$age = $_POST["data"]["1st"].$_POST["data"]["2nd"];
	$age2 = $_POST["data"]["1st"].".".$_POST["data"]["2nd"];
	$sex = $_POST["sex"];
	$mStatus = $_POST["mstat"];
	$relation = $_POST["data"]["relation"];
	$schooling = $_POST["data"]["s1"].$_POST["data"]["s2"];
	$sType = $_POST["data"]["st"];
	$occupation = $_POST["data"]["occupation"];
	
	$data = $age2.",".$sex.",".$mStatus.",".$relation.",".$schooling.",".$occupation;
	
	$sql="UPDATE raw_data set q2='$age', q3='$sex', q4='$mStatus', q5='$relation', q6='$schooling', q7='$occupation', q8='$sType', is_completed='0' WHERE id='$resId' and user_id='$user_id' and hid ='$hid'";
	mysql_query($sql) or die ("problem 2ND BLOCK OF RESPONDENT");
	//exit;
	
	
	$sql="UPDATE track set qid='7' WHERE appid='$resId' and user_id='$user_id' and hid = '$hid'";
	mysql_query($sql) or die ("problem budget_heads");
	
	if($sex==''||$mStatus==''||$relation=='00'||$occupation=='00'){
		header( "location: qus1.php?serial=2" );
	}
	else{
		$_SESSION['rm2']=1;
		header( "location: qus4.php?serial=a" );
	}
  }
  else if($qus_no =='4_a'){
  	 $name = $_POST["data"]["name"];
	 $completed_id = $_SESSION['completed_id'];
	//echo $ABC;
	//exit;
	 //$completed = $_POST['completed'];
	 $back=$_POST['done'];
	//exit;
	if($name !='None' and $back !='Done'){
	
	     if($_SESSION['rm2']=='1'){
			$sql="UPDATE raw_data set is_completed='1' WHERE id='$completed_id'";
			 mysql_query($sql) or die ("problem 2ND BLOCK OF RESPONDENT");
			 $_SESSION['rm2']=0;
		 }
		 
		 $sql="SELECT is_completed from raw_data  WHERE id='$completed_id' ";
		 $result= mysql_query($sql);
		 $row = mysql_fetch_assoc($result);
		 $completed=$row['is_completed'];
		 
		 
		 
		 
		if($completed=='0'){
			$sql="UPDATE raw_data set q1='$name' WHERE id='$completed_id'";
			mysql_query($sql) or die ("problem on updating household");	
			$lidinsert= mysql_insert_id();
			$sql="Delete from track WHERE appid='$resId' and user_id='$user_id' and hid = '$hid'";
			mysql_query($sql) or die ("problem budget_heads");	
			
			$sql="INSERT INTO track (id, user_id, hid, appid, qid, is_delete, status) VALUES ('', '$user_id','$hid','$lidinsert', 'a', 0, 1)";
			mysql_query($sql) or die ("problem budget_heads");
			$_SESSION['lid']=$lidinsert;
			$sql="INSERT INTO lastid (id,user_id,hid,status) VALUES ('$lidinsert',$user_id,$hid,0)";
			mysql_query($sql) or die ("problem budget_heads");			
			header( "location: qus4.php?serial=b" );		
		}
		else{
			$sql="INSERT INTO raw_data (id, rid, user_id, hid, q1, q2, q3, q4, q5, q6, q7, q8, is_delete, status) VALUES ('', '2', '$user_id','$hid','$name', '00', '0', '0', '0', '00', '00', '0', 0, 0)";
			mysql_query($sql) or die ("problem budget_heads");
			$lidinsert= mysql_insert_id();
			$_SESSION['completed_id']=$lidinsert;
			$sql="Delete from track WHERE appid='$resId' and user_id='$user_id' and hid = '$hid'";
			mysql_query($sql) or die ("problem budget_heads");
			
			$sql="INSERT INTO track (id, user_id, hid, appid, qid, is_delete, status) VALUES ('', '$user_id','$hid','$lidinsert', 'a', 0, 1)";
			mysql_query($sql) or die ("problem budget_heads");
			$_SESSION['lid']=$lidinsert;
			$sql="INSERT INTO lastid (id,user_id,hid,status) VALUES ('$lidinsert',$user_id,$hid,0)";
			mysql_query($sql) or die ("problem budget_heads");
			header( "location: qus4.php?serial=b" );
		}
	}
	else if($name =="None" and $back =="Done"){
		$lastdata = mysql_query(" select id from lastid where user_id='$user_id' and hid ='$hid' order by id desc");
		$linkarray = mysql_fetch_array($lastdata);
		$linkid = $linkarray['id'];
		$sql="UPDATE track set qid='rel_detail' WHERE appid='$linkid' and user_id='$user_id' and hid = '$hid'";
		mysql_query($sql) or die ("problem delete last record track");
		header( "location: rel_detail.php" );
	}
	else if($name =="None" and $back !="Done"){
		header( "location: qus4.php?serial=a" );
	}
	else if($name !='None' and $back =='Done'){
		header( "location: qus4.php?serial=a" );
	}
  }
  else if($qus_no =='4_b'){
  	$age = $_POST["data"]["1st"].$_POST["data"]["2nd"];
	$sex = $_POST["sex"];
	$mStatus = $_POST["mstat"];
	$relation = $_POST["data"]["relation"];
	$schooling = $_POST["data"]["s1"].$_POST["data"]["s2"];
	$schoolType = $_POST["data"]["st"];
	$occupation = $_POST["data"]["occupation"];
	//$data = $age.",".$sex.",".$mStatus.",".$relation.",".$schooling.",".$occupation;
	
	$sql="UPDATE raw_data set q2='$age', q3='$sex', q4='$mStatus', q5='$relation', q6='$schooling', q7='$occupation', q8='$schoolType', is_completed='0' WHERE id='$resId' and user_id='$user_id' and  hid = '$hid'";
	mysql_query($sql) or die ("problem 2ND BLOCK OF members");
	
	$sql="UPDATE track set qid='g' WHERE appid='$resId' and user_id='$user_id' and hid = '$hid'";
	mysql_query($sql) or die ("problem budget_heads");
	
	if($sex==''||$mStatus==''||$relation=='00'||$occupation=='00'){
		header( "location: qus4.php?serial=b" );
	}
	else{
		$_SESSION['rm2']=1;
	    header( "location: qus4.php?serial=a" );
		}
			
  }
  else if($qus_no =='ret'){
	$hhhid = $_POST["HHHid"];
	$search_id=$_POST['search_id'];	
	header( "location: retrieve_detail.php?hhid=$hhhid&search_id=$search_id" );
  }
  else if($qus_no =='upd'){
   $hhhid = $_POST["HHHid"];
   $block = $_POST['block'];
   		if($block=='4'){
   			header( "location: update/update_hc.php?hhid=$hhhid&bid=$block" );
   		}
		elseif($block=='5'){
   			header( "location: update/update_asset.php?hhid=$hhhid&bid=$block" );
   		}
		elseif($block=='6'){
   			header( "location: update/update_economic.php?hhid=$hhhid&bid=$block" );
   		}
   		else{
   			header( "location: update/update_detail.php?hhid=$hhhid&bid=$block" );
		}	
	//header( "location: update_detail.php?hhid=$hhhid&bid=$block" );
  }
  else if($qus_no =='rel_detail'){
	$back=$_POST['stn'];
	if($back==''){
		header( "location: rel_detail.php" );
		exit;
	}
	$value = explode(":",$back);
	$_SESSION['relOf']=$value[0];
	$_SESSION['name']=$value[1];
	$sql="UPDATE track set qid='rel_detail' WHERE appid='$resId' and user_id='$user_id' and hid = '$hid'";
	mysql_query($sql) or die ("problem budget_heads");
	header( "location: rel_detail2.php?id=$value[0]&name=$value[1]" );
  }
  else if($qus_no =='rel_detail2'){
	$fid = $_POST['fid'];
	$mid = $_POST['mid'];
	$sid = $_POST['sid'];
	$stid = $_POST['ss1'].$_POST['ss2'];
	$oid = $_POST['oid'];
	$appid = $_SESSION['relOf'];
	$nameid= $_SESSION['name'];
	$go = $_POST['back'];
	$sql="UPDATE raw_data set q9='$fid',status='1' WHERE id='$appid' and user_id='$user_id' and hid = '$hid'";	
	mysql_query($sql) or die ("problem father");
	
	$sql="UPDATE raw_data set q10='$mid',status='1' WHERE id='$appid' and user_id='$user_id' and hid = '$hid'";	
	mysql_query($sql) or die ("problem mother");
	
	$sql="UPDATE raw_data set q11='$sid',status='1' WHERE id='$appid' and user_id='$user_id' and hid = '$hid'";	
	mysql_query($sql) or die ("problem spouse");
		
	if($go=='Next'){
		if($sid=='Deceased'||$sid=='Lives elsewhere'){
			header( "location: rel_detail3.php?id=$appid&name=$nameid" );
		}
		else{
			header( "location: rel_detail.php" );
		}
	}
	else{
		if($sid=='Deceased'||$sid=='Lives elsewhere'){
			header( "location: rel_detail3.php?id=$appid&name=$nameid" );
		}
		else{
				if(isset($_SESSION['lid'])){
				$sql="UPDATE track set qid='hc_1' WHERE appid='$resId' and user_id='$user_id' and hid = '$hid'";
				mysql_query($sql) or die ("problem budget_heads");
				unset($_SESSION['lid']);
			}
			//header( "location: hc_info.php?serial=1" );
			header( "location: qus5.php?serial=a" );
		}
	}
  }
  else if($qus_no =='rel_detail3'){
  	$SchType = $_POST['st'];
	$stid = $_POST['ss1'].$_POST['ss2'];
	$oid = $_POST['oid'];
	$appid = $_SESSION['relOf'];
	$go = $_POST['back'];
	
	$sql="UPDATE raw_data set q12='$SchType',status='1' WHERE id='$appid' and user_id='$user_id' and hid = '$hid'";	
	mysql_query($sql) or die ("problem spouse education");	
	
	$sql="UPDATE raw_data set q13='$stid',status='1' WHERE id='$appid' and user_id='$user_id' and hid = '$hid'";	
	mysql_query($sql) or die ("problem spouse education");
	
	$sql="UPDATE raw_data set q14='$oid',status='1' WHERE id='$appid' and user_id='$user_id' and hid = '$hid'";	
	mysql_query($sql) or die ("problem spouse occupation");	
	if($go=='Next'){		
			header( "location: rel_detail.php" );
	}
	else{
		if(isset($_SESSION['lid'])){
			$sql="delete from track WHERE appid='$resId' and user_id='$user_id' and hid = '$hid'";
			mysql_query($sql) or die ("problem budget_heads");
			unset($_SESSION['lid']);
		}
		//header( "location: hc_info.php?serial=1" );
		header( "location: qus5.php?serial=a" );
	}
  }
  else if($qus_no =='5_a'){
	 $cod = $_POST["cod1"];
	 if($cod==0){
		header( "location: qus5.php?serial=a" );
	 }
	 else if($cod==1){
		header( "location: qus5.php?serial=b" );
	 }
	 else{
		header( "location: hc_info.php?serial=1" );
	 }
   }
   else if($qus_no =='5_b'){
  	 $name = $_POST["data"]["name"];
	 $back=$_POST['done'];
	//exit;
	if($name !='None' and $back !='Done'){
		$sql="INSERT INTO cod (id, rid, user_id, hid, q1, is_delete, status) VALUES ('', '2', '$user_id','$hid','$name', 0, 0)";
		mysql_query($sql) or die ("problem budget_heads");
		$lidinsert= mysql_insert_id();
		$sql="Delete from track WHERE appid='$resId' and user_id='$user_id' and hid = '$hid'";
		mysql_query($sql) or die ("problem budget_heads");
		
		$sql="INSERT INTO track (id, user_id, hid, appid, qid, is_delete, status) VALUES ('', '$user_id','$hid','$lidinsert', 'a', 0, 1)";
		mysql_query($sql) or die ("problem budget_heads");
		$_SESSION['lid']=$lidinsert;
		$sql="INSERT INTO lastid (id,user_id,hid,status) VALUES ('$lidinsert',$user_id,$hid,0)";
		mysql_query($sql) or die ("problem budget_heads");
		$sql="SELECT * FROM cod WHERE user_id='$user_id' and hid='$hid' ORDER BY id DESC limit 1";
		$result=mysql_query($sql) or die ("problem budget_heads");
		$row=mysql_fetch_assoc($result);
		$id=$row['id'];
		header( "location: qus5.php?serial=c&id=$id" );
	}
	else if($name =="None" and $back =="Done"){
		$lastdata = mysql_query(" select id from lastid where user_id='$user_id' and hid ='$hid' order by id desc");
		$linkarray = mysql_fetch_array($lastdata);
		$linkid = $linkarray['id'];
		$sql="UPDATE track set qid='rel_detail' WHERE appid='$linkid' and user_id='$user_id' and hid = '$hid'";
		mysql_query($sql) or die ("problem delete last record track");
		//header( "location: rel_detail.php" );
		header( "location: hc_info.php?serial=1" );
	}
	else if($name =="None" and $back !="Done"){
		header( "location: qus5.php?serial=b" );
	}
	else if($name !='None' and $back =='Done'){
		header( "location: qus5.php?serial=b" );
	}
  }
  else if($qus_no =='5_c'){
  		$id=$_POST['id'];
		$age = $_POST["data"]["1st"].$_POST["data"]["2nd"];
		$sex = $_POST["sex"];
		$mStatus = $_POST["mstat"];
		$relation = $_POST["data"]["relation"];
		$schooling = $_POST["data"]["s1"].$_POST["data"]["s2"];
		$schoolType = $_POST["data"]["st"];
		$occupation = $_POST["data"]["occupation"];
		$cod09 = $_POST["data"]["cod09"];
		$cod10 = $_POST["data"]["cod10"];
		$cod11 = $_POST["data"]["cod11"];
		$cod12 = $_POST["data"]["cod12"];
		$cod13 = $_POST["data"]["cod13"];
		$cod14 = $_POST["data"]["cod14"];
		$cod15 = $_POST["data"]["cod15"];
		$cod16 = $_POST["data"]["cod16"];
		//$data = $age.",".$sex.",".$mStatus.",".$relation.",".$schooling.",".$occupation;
		
		$sql="UPDATE cod set q2='$age', q3='$sex', q4='$mStatus', q5='$relation', q6='$schooling', q7='$occupation', q8='$schoolType', cod09='$cod09', cod10='$cod10', cod11='$cod11', cod12='$cod12', cod13='$cod13',  cod14='$cod14',  cod15='$cod15', cod16='$cod16' WHERE id='$id' and user_id='$user_id' and hid = '$hid'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		
		$sql="UPDATE track set qid='g' WHERE appid='$resId' and user_id='$user_id' and hid = '$hid'";
		mysql_query($sql) or die ("problem budget_heads");
		
		if($sex==''||$mStatus==''||$relation=='00'||$occupation=='00'){
			header( "location: qus5.php?serial=c" );
		}
		else{
			header( "location: qus5.php?serial=b" );
		}	
  }
  else if($qus_no =='12'){
	    $time = date('Y-m-d H:i:s',strtotime("+10 hours"));
  		$rent = $_POST["data"]["1st"].$_POST["data"]["2nd"];
		$sql="UPDATE raw_data set q11='$rent' WHERE id='$resId' and user_id='$user_id' and hid = '$hid'";
		mysql_query($sql) or die ("problem budget_heads");
		$hcsql="UPDATE elapsed_time SET end_time='$time' WHERE hhid='$hid'";
			mysql_query($hcsql) or die ("problem timing");
		$sql="UPDATE track set qid='11' WHERE appid='$resId' and user_id='$user_id' and hid = '$hid'";
		mysql_query($sql) or die ("problem rent");
		header( "location: qus4.php?serial=a" );		
  }
  else if($qus_no == 'hc'){
	  $time = date('Y-m-d H:i:s',strtotime("+10 hours"));
  	 $env1 = $_POST['hc01_01'];
	 $env2 = $_POST['hc01_02'];
	 $env3 = $_POST['hc01_03'];
	 $env4 = $_POST['hc01_04']; 
	 $room = $_POST['r1'].$_POST['r2'];
	 $bedType = $_POST['htype'];
	 $wallType = $_POST['wall'];
	 $roofType = $_POST['roof'];
	 $hcurrent = $_POST['hcurrent'];
	 $vcurrent = $_POST['vcurrent'];
	 
	 $sql="UPDATE household_info SET hc01_1='$env1', hc01_2='$env2', hc01_3='$env3', hc01_4='$env4', hc04='$room', hc05='$bedType', hc06='$wallType', hc07='$roofType', hc08='$hcurrent', hc09='$vcurrent' WHERE hid='$hid'";
		mysql_query($sql) or die ("problem budget_heads");
	 
	 if($env1==''||$env2==''||$env3==''||$env4==''||$room=='00'||$env1==''||$bedType==''||$roofType==''||$hcurrent==''||$vcurrent==''){
	 header( "location: hc_info.php?serial=1" );
   }
   	else{
		$hcsql="UPDATE elapsed_time SET end_time='$time' WHERE hhid='$hid'";
			mysql_query($hcsql) or die ("problem timing");
		$sql="UPDATE track set qid='hc_2' WHERE appid='$resId' and user_id='$user_id' and hid = '$hid'";
		mysql_query($sql) or die ("problem budget_heads");
		header( "location: hc_info.php?serial=2" );
	}
  }
  else if($qus_no == 'hc_1'){
	  	$time = date('Y-m-d H:i:s',strtotime("+10 hours"));
  		$owner_home = $_POST['owner'];
		
		if($owner_home == '0'){
			header( "location: hc_info.php?serial=2" );
		}
		elseif($owner_home == '1'||$owner_home=='2'){
			$sql="UPDATE household_info set hc02='$owner_home' WHERE hid='$hid'";
			mysql_query($sql) or die ("problem rent");
			$sql="UPDATE track set qid='hc_4' WHERE appid='$resId' and user_id='$user_id' and hid = '$hid'";
			mysql_query($sql) or die ("problem budget_heads");
			header( "location: hc_info.php?serial=4" );
			//echo $owner_home;
		}
		else{
			$sql="UPDATE household_info set hc02='$owner_home' WHERE hid='$hid'";
			mysql_query($sql) or die ("problem rent");
			$hcsql="UPDATE elapsed_time SET end_time='$time' WHERE hhid='$hid'";
			mysql_query($hcsql) or die ("problem timing");
			$sql="UPDATE track set qid='hc_3' WHERE appid='$resId' and user_id='$user_id' and hid = '$hid'";
			mysql_query($sql) or die ("problem budget_heads");
			header( "location: hc_info.php?serial=3" );
			
		}
	}
	else if($qus_no == 'hc_2'){
  		//$rent = $_POST['rent'];
		$time = date('Y-m-d H:i:s',strtotime("+10 hours"));
		$rent = $_POST['rent1'].$_POST['rent2'];
		if($rent==''){
			$sql="UPDATE track set qid='hc_3' WHERE appid='$resId' and user_id='$user_id' and hid = '$hid'";
			mysql_query($sql) or die ("problem budget_heads");
			header( "location: hc_info.php?serial=3" );
		}
		else{	
			$sql="UPDATE household_info set hc03='$rent' WHERE hid='$hid'";
			mysql_query($sql) or die ("problem rent");
			$hcsql="UPDATE elapsed_time SET end_time='$time' WHERE hhid='$hid'";
			mysql_query($hcsql) or die ("problem timing");
			$sql="UPDATE track set qid='hc_4' WHERE appid='$resId' and user_id='$user_id' and hid = '$hid'";
			mysql_query($sql) or die ("problem budget_heads");
			header( "location: hc_info.php?serial=4" );
			//echo $owner_home;
		}
	} 
	else if($qus_no == 'hc_3'){
		 $time = date('Y-m-d H:i:s',strtotime("+10 hours"));
		 $hc10 = $_POST['drink'];
		 if($hc10=='00'){
				header( "location: hc_info.php?serial=4" );
		 }
		 else{
			 $sql="UPDATE household_info set hc10='$hc10' WHERE hid='$hid'";
			 mysql_query($sql) or die ("problem rent");
			 $hcsql="UPDATE elapsed_time SET end_time='$time' WHERE hhid='$hid'";
			mysql_query($hcsql) or die ("problem timing");
			 $sql="UPDATE track set qid='hc_4a_&source=$hc10' WHERE appid='$resId' and user_id='$user_id' and hid = '$hid'";
			 mysql_query($sql) or die ("problem budget_heads");
			 header( "location: hc_info.php?serial=4a&source=$hc10" );
		 }
		
	} 
	else if($qus_no == 'hc_3a'){
		 //$hc10 = $_POST['drink'];
		 $time = date('Y-m-d H:i:s',strtotime("+10 hours"));
		 $source=$_POST['dsource'];
		 $hc11=$_POST['pwater'];
		 $hc12=$_POST['t1'].$_POST['t2'];
		 if($hc11=='0'){
				header( "location: hc_info.php?serial=4a&source=$source" );
		 }
		 elseif($hc11=='3'&&$hc12=='00'){
				header( "location: hc_info.php?serial=4a&source=$source" );
		 }
		 else{	 
			$sql="UPDATE household_info set  hc11='$hc11', hc12='$hc12' WHERE hid='$hid'";
			mysql_query($sql) or die ("problem rent");
			$hcsql="UPDATE elapsed_time SET end_time='$time' WHERE hhid='$hid'";
			mysql_query($hcsql) or die ("problem timing");
			$sql="UPDATE track set qid='hc_5' WHERE appid='$resId' and user_id='$user_id' and hid = '$hid'";
			mysql_query($sql) or die ("problem budget_heads");
			header( "location: hc_info.php?serial=5" );
		}
		
	}
	else if($qus_no=='hc_4'){
		$time = date('Y-m-d H:i:s',strtotime("+10 hours"));
		 $hc13=$_POST['washing'];
		 if($hc13=='00'){
				header( "location: hc_info.php?serial=5" );
		 }
		 else{		
			 $sql="UPDATE household_info set hc13='$hc13' WHERE hid='$hid'";
			 mysql_query($sql) or die ("problem rent");
			 $hcsql="UPDATE elapsed_time SET end_time='$time' WHERE hhid='$hid'";
			mysql_query($hcsql) or die ("problem timing");
			 $sql="UPDATE track set qid='hc_5a_&wsource=$hc13' WHERE appid='$resId' and user_id='$user_id' and hid = '$hid'";
			mysql_query($sql) or die ("problem budget_heads");
			 header( "location: hc_info.php?serial=5a&wsource=$hc13" );
		 }
	}
	else if($qus_no=='hc_4a'){
		$time = date('Y-m-d H:i:s',strtotime("+10 hours"));
		 $wsource=$_POST['wsource'];
		 $hc14=$_POST['wpwater'];
		 $hc15=$_POST['t3'].$_POST['t4'];	
		 if($hc14=='0'){
				header( "location: hc_info.php?serial=5a&wsource=$wsource" );
		 }
		 elseif($hc14=='3'&&$hc15=='00'){
				header( "location: hc_info.php?serial=5a&wsource=$wsource" );
		 }
		 else{			
			$sql="UPDATE household_info set hc14='$hc14', hc15='$hc15' WHERE hid='$hid'";
			mysql_query($sql) or die ("problem rent");
			$hcsql="UPDATE elapsed_time SET end_time='$time' WHERE hhid='$hid'";
			mysql_query($hcsql) or die ("problem timing");
			$sql="UPDATE track set qid='hc_6' WHERE appid='$resId' and user_id='$user_id' and hid = '$hid'";
			mysql_query($sql) or die ("problem budget_heads");
			header( "location: hc_info.php?serial=6" );
		}
	}
	else if($qus_no=='hc_5'){
		$time = date('Y-m-d H:i:s',strtotime("+10 hours"));
		$hc16=$_POST['fuel'];
		 //$hc16_o=$_POST['ofuel'];
		$hc17=$_POST['hc17'];
		$hc18=$_POST['hc18'];
		$hc19=$_POST['m1'].$_POST['m2'];
		
		$sql="UPDATE household_info set h16='$hc16', h17='$hc17', h18='$hc18', h19='$hc19' WHERE hid='$hid'";
			mysql_query($sql) or die ("problem rent");	
				
		if($hc17!='1' && $hc19=='00'){
			header( "location: hc_info.php?serial=6" );
		}
		else if($hc16=='0'||$hc17=='0'||$hc18=='0'){
				header( "location: hc_info.php?serial=6" );
		 }
		 else{
			 $hcsql="UPDATE elapsed_time SET end_time='$time' WHERE hhid='$hid'";
			mysql_query($hcsql) or die ("problem timing");
		 	$sql="UPDATE track set qid='hc_7' WHERE appid='$resId' and user_id='$user_id' and hid = '$hid'";
			mysql_query($sql) or die ("problem budget_heads");			
			header( "location: hc_info.php?serial=7" );
		}
	}
	else if($qus_no=='hc_6'){
		$time = date('Y-m-d H:i:s',strtotime("+10 hours"));
		$hc20_1=$_POST['h20_m'];
		$hc21_1=$_POST['h21_m'];
		$hc22_1=$_POST['h22_m'];
		$hc23_1=$_POST['h23_m'];
		
		$sql="UPDATE household_info set h20_01='$hc20_1', h21_01='$hc21_1', h22_01='$hc22_1', h23_01='$hc23_1' WHERE hid='$hid'";
		mysql_query($sql) or die ("problem rent");
		
		if($hc20_1=='0'||$hc21_1==''||$hc22_1=='0'||$hc23_1=='0'){
				header( "location: hc_info.php?serial=7" );
		 }
		 else{
			 $hcsql="UPDATE elapsed_time SET end_time='$time' WHERE hhid='$hid'";
			mysql_query($hcsql) or die ("problem timing");
			$sql="UPDATE track set qid='hc_8' WHERE appid='$resId' and user_id='$user_id' and hid = '$hid'";
			mysql_query($sql) or die ("problem budget_heads");
			header( "location: hc_info.php?serial=8" );
		}
		
		
	}
	else if($qus_no=='hc_7'){
		$time = date('Y-m-d H:i:s',strtotime("+10 hours"));
		$hc24=$_POST['h24'];
		$hc26=$_POST['h26'];
		$hc27=$_POST['h27'];
		$sql="UPDATE household_info set h24='$hc24', h26='$hc26', h27='$hc27' WHERE hid='$hid'";
			mysql_query($sql) or die ("problem rent");
		if($hc24==''||$hc26=='-1'||$hc27=='0'){
				header( "location: hc_info.php?serial=8" );
		 }
		 else{
			 $hcsql="UPDATE elapsed_time SET end_time='$time' WHERE hhid='$hid'";
			mysql_query($hcsql) or die ("problem timing");
		 	$sql="UPDATE track set qid='hc_9' WHERE appid='$resId' and user_id='$user_id' and hid = '$hid'";
			mysql_query($sql) or die ("problem budget_heads");
			header( "location: hc_info.php?serial=9" );
		}
		
	}
	else if($qus_no=='hc_8'){
		$time = date('Y-m-d H:i:s',strtotime("+10 hours"));
		$hc28_a_1=$_POST['h28_a_1'];
		$hc28_b_1=$_POST['h28_b_1'];
		$hc28_c_1=$_POST['h28_c_1'];
		
		$sql="UPDATE household_info set h28_a_1='$hc28_a_1', h28_b_1='$hc28_b_1', h28_c_1='$hc28_c_1' WHERE hid='$hid'";
			mysql_query($sql) or die ("problem rent");
				
		if($hc28_a_1=='0'||$hc28_b_1=='0'||$hc28_c_1=='0'){
				header( "location: hc_info.php?serial=9" );
		 }
		 else{
			$hcsql="UPDATE elapsed_time SET end_time='$time' WHERE hhid='$hid'";
			mysql_query($hcsql) or die ("problem timing");
		 	$sql="UPDATE track set qid='hc_10' WHERE appid='$resId' and user_id='$user_id' and hid = '$hid'";
			mysql_query($sql) or die ("problem budget_heads");
			header( "location: hc_info.php?serial=10" );
		}
		
	}
	else if($qus_no=='hc_9'){
		$time = date('Y-m-d H:i:s',strtotime("+10 hours"));
		$hc29 = $_POST['h29'];
		$hc30 = $_POST['h30'];
		$hc31 = $_POST['h31'];
		$hc32 = $_POST['h32'];
		
		$sql="UPDATE household_info set h29='$hc29', h30='$hc30', h31='$hc31', h32='$hc32' WHERE hid='$hid'";
			mysql_query($sql) or die ("problem rent");
			
		if($hc29==''||$hc30==''){
				header( "location: hc_info.php?serial=10" );
		 }
		 elseif($hc31!='No'&&$hc32==''){
				header( "location: hc_info.php?serial=10" );
		 }	 
		 else{
			 $hcsql="UPDATE elapsed_time SET end_time='$time' WHERE hhid='$hid'";
			mysql_query($hcsql) or die ("problem timing");
		 	$sql="UPDATE track set qid='hc_11' WHERE appid='$resId' and user_id='$user_id' and hid = '$hid'";
			mysql_query($sql) or die ("problem budget_heads");
			header( "location: hc_info.php?serial=11" );
		}
		
	}
	else if($qus_no=='hc_10'){
		$time = date('Y-m-d H:i:s',strtotime("+10 hours"));
		$ha_01 = $_POST['ha_1'];
		$ha_02 = $_POST['ha_2'];
		$ha_03 = $_POST['ha_3'];
		$ha_04 = $_POST['ha_4'];
		$ha_05 = $_POST['ha_5'];
		$ha_06 = $_POST['ha_6'];
		$ha_07 = $_POST['ha_7'];
		$ha_08 = $_POST['ha_8'];
		$ha_09 = $_POST['ha_9'];
		$ha_10 = $_POST['ha_10'];
		$ha_11 = $_POST['ha_11'];
		$ha_12 = $_POST['ha_12'];
		$ha_13 = $_POST['ha_13'];
		$ha_14 = $_POST['ha_14'];
		$ha_15 = $_POST['ha_15'];
		$ha_16 = $_POST['ha_16'];
		$ha_17 = $_POST['ha_17'];
		$ha_18 = $_POST['ha_18'];
		$ha_19 = $_POST['ha_19'];
		$ha_20 = $_POST['ha_20'];
		$ha_21 = $_POST['ha_21'];
		$ha_22 = $_POST['ha_22'];
		$ha_23 = $_POST['ha_23'];
		
		/*$sql="INSERT INTO household_asset (id,  hid, ha_01, ha_02, ha_03, ha_04, ha_05, ha_06, ha_07, ha_08, ha_09, ha_10, ha_11, ha_12, ha_13, ha_14, ha_15, ha_16, ha_17, ha_18, ha_19, ha_20, ha_21, ha_22, ha_23, is_delete, status) 
		VALUES 
		('',  '$hid', '$ha_01', '$ha_02', '$ha_03', '$ha_04', '$ha_05', '$ha_06', '$ha_07', '$ha_08',' $ha_09', '$ha_10', '$ha_11', '$ha_12', '$ha_13', '$ha_14', '$ha_15', '$ha_16', '$ha_17', '$ha_18', '$ha_19', '$ha_20', '$ha_21', '$ha_22', '$ha_23',  0, 0)";*/
		$sql="UPDATE household_asset SET ha_01='$ha_01', ha_02='$ha_02', ha_03='$ha_03', ha_04='$ha_04', ha_05='$ha_05', ha_06='$ha_06', ha_07='$ha_07', ha_08='$ha_08', ha_09='$ha_09', ha_10='$ha_10', ha_11='$ha_11', ha_12='$ha_12', ha_13='$ha_13', ha_14='$ha_14', ha_15='$ha_15', ha_16='$ha_16', ha_17='$ha_17', ha_18='$ha_18', ha_19='$ha_19', ha_20='$ha_20', ha_21='$ha_21', ha_22='$ha_22', ha_23='$ha_23' where hid='$hid'";
		mysql_query($sql) or die ("problem budget_heads");
		
		$hcsql="UPDATE elapsed_time SET end_time='$time' WHERE hhid='$hid'";
			mysql_query($hcsql) or die ("problem timing");
			
		$sql="UPDATE track set qid='hc_12' WHERE appid='$resId' and user_id='$user_id' and hid = '$hid'";
		mysql_query($sql) or die ("problem budget_heads");
		header( "location: hc_info.php?serial=12" );
	}
	else if($qus_no=='hc_11'){
		$time = date('Y-m-d h:i:s',strtotime("+6 hours"));
		$heh_01_a = $_POST['heh_1_a'];
		$heh_01_b = $_POST['heh_1_b'];
		$heh_01_c = $_POST['heh_1_c'];
		$heh_01_d = $_POST['heh_1_d'];
		$heh_01_e = $_POST['heh_1_e'];
		$heh_01_f = $_POST['heh_1_f'];
		$heh_01_g = $_POST['heh_1_g'];
		
		$qstring = "&a=$heh_01_a&b=$heh_01_b&c=$heh_01_c&d=$heh_01_d&e=$heh_01_e&f=$heh_01_f&g=$heh_01_g";
		
		$sql="UPDATE household_economic SET heh01_a='$heh_01_a', heh01_b='$heh_01_b', heh01_c='$heh_01_c', heh01_d='$heh_01_d', heh01_e='$heh_01_e', heh01_f='$heh_01_f', heh01_g='$heh_01_g' WHERE hid='$hid'";
			mysql_query($sql) or die ("problem budget_heads");
			
		if($heh_01_a=='0'||$heh_01_b=='0'||$heh_01_c=='0'||$heh_01_d=='0'||$heh_01_e=='0'||$heh_01_f=='0'||$heh_01_g=='0'){
			header( "location: hc_info.php?serial=12" );
		}
		else if($heh_01_a=='3' and $heh_01_b=='3'and $heh_01_c=='3'and $heh_01_d=='3'and $heh_01_e=='3'and $heh_01_f=='3'and $heh_01_g=='3'){
			header( "location: hc_info.php?serial=16" );
		}
		else{
			$hcsql="UPDATE elapsed_time SET end_time='$time' WHERE hhid='$hid'";
			mysql_query($hcsql) or die ("problem timing");
			$sql="UPDATE track set qid='hc_13_do_:$qstring' WHERE appid='$resId' and user_id='$user_id' and hid = '$hid'";
			mysql_query($sql) or die ("problem budget_heads");
			header( "location: hc_info.php?serial=13$qstring" );
		}
	}
	else if($qus_no=='hc_12'){
		$time = date('Y-m-d h:i:s',strtotime("+6 hours"));
		$heh_02_a = $_POST['heh_2_a'];
		if($heh_02_a =='3'||$heh_02_a =='')$heh_02_a='3';
		$heh_02_b = $_POST['heh_2_b'];
		if($heh_02_b =='3'||$heh_02_b =='')$heh_02_b='3';
		$heh_02_c = $_POST['heh_2_c'];
		if($heh_02_c =='3'||$heh_02_c =='')$heh_02_c='3';
		$heh_02_d = $_POST['heh_2_d'];
		if($heh_02_d =='3'||$heh_02_d =='')$heh_02_d='3';
		$heh_02_e = $_POST['heh_2_e'];
		if($heh_02_e =='3'||$heh_02_e =='')$heh_02_e='3';
		$heh_02_f = $_POST['heh_2_f'];
		if($heh_02_f =='3'||$heh_02_f =='')$heh_02_f='3';
		$heh_02_g = $_POST['heh_2_g'];
		if($heh_02_g =='3'||$heh_02_g =='')$heh_02_g='3';
		$bstring=$_POST['bstring'];
		$qstring = "&a=$heh_02_a&b=$heh_02_b&c=$heh_02_c&d=$heh_02_d&e=$heh_02_e&f=$heh_02_f&g=$heh_02_g";
		
		$sql="UPDATE household_economic SET heh02_a='$heh_02_a', heh02_b='$heh_02_b', heh02_c='$heh_02_c', heh02_d='$heh_02_d', heh02_e='$heh_02_e', heh02_f='$heh_02_f', heh02_g='$heh_02_g' WHERE hid='$hid'";
			mysql_query($sql) or die ("problem budget_heads");
		
		if($heh_02_a=='0'||$heh_02_b=='0'||$heh_02_c=='0'||$heh_02_d=='0'||$heh_02_e=='0'||$heh_02_f=='0'||$heh_02_g=='0'){
			header( "location: hc_info.php?serial=13$bstring" );
		}
		else if($heh_02_a=='3' and $heh_02_b=='3'and $heh_02_c=='3'and $heh_02_d=='3'and $heh_02_e=='3'and $heh_02_f=='3'and $heh_02_g=='3'){
			header( "location: hc_info.php?serial=16" );
		}
		else{
			$hcsql="UPDATE elapsed_time SET end_time='$time' WHERE hhid='$hid'";
			mysql_query($hcsql) or die ("problem timing");
			$sql="UPDATE track set qid='hc_14_do_:$qstring' WHERE appid='$resId' and user_id='$user_id' and hid = '$hid'";
			mysql_query($sql) or die ("problem budget_heads");
			header( "location: hc_info.php?serial=14$qstring" );
		}
	}
	else if($qus_no=='hc_13'){
		$time = date('Y-m-d h:i:s',strtotime("+6 hours"));
		$heh_03_a = $_POST['month_a'];
		$heh_03_b = $_POST['month_b'];
		$heh_03_c = $_POST['month_c'];
		$heh_03_d = $_POST['month_d'];
		$heh_03_e = $_POST['month_e'];
		$heh_03_f = $_POST['month_f'];
		$heh_03_g = $_POST['month_g'];
		
		//echo"<pre>";
		//print_r($_POST);
		
		$qstring = $_POST['qstr'];
		
		$sql="UPDATE household_economic SET heh03_a='$heh_03_a', heh03_b='$heh_03_b', heh03_c='$heh_03_c', heh03_d='$heh_03_d', heh03_e='$heh_03_e', heh03_f='$heh_03_f', heh03_g='$heh_03_g' WHERE hid='$hid'";
			mysql_query($sql) or die ("problem budget_heads");
		
		if($heh_03_a=='0'||$heh_03_b=='0'||$heh_03_c=='0'||$heh_03_d=='0'||$heh_03_e=='0'||$heh_03_f=='0'||$heh_03_g=='0'){
			//echo "hello";
			header( "location: hc_info.php?serial=14$qstring" );
		}
		else{
			$hcsql="UPDATE elapsed_time SET end_time='$time' WHERE hhid='$hid'";
			mysql_query($hcsql) or die ("problem timing");
			$sql="UPDATE track set qid='hc_15_do_:$qstring' WHERE appid='$resId' and user_id='$user_id' and hid = '$hid'";
			mysql_query($sql) or die ("problem budget_heads");		
			header( "location: hc_info.php?serial=15$qstring" );
		}
	}
	else if($qus_no=='hc_14'){
		$time = date('Y-m-d h:i:s',strtotime("+6 hours"));
		$heh_04_a = $_POST['heh_4_a'];
		$heh_04_b = $_POST['heh_4_b'];
		$heh_04_c = $_POST['heh_4_c'];
		$heh_04_d = $_POST['heh_4_d'];
		$heh_04_e = $_POST['heh_4_e'];
		$heh_04_f = $_POST['heh_4_f'];
		$heh_04_g = $_POST['heh_4_g'];
		
		$qstring = $_POST['qstr'];
		
		
		$sql="UPDATE household_economic SET heh04_a='$heh_04_a', heh04_b='$heh_04_b', heh04_c='$heh_04_c', heh04_d='$heh_04_d', heh04_e='$heh_04_e', heh04_f='$heh_04_f', heh04_g='$heh_04_g' WHERE hid='$hid'";
		mysql_query($sql) or die ("problem budget_heads");
		if($heh_04_a=='0'||$heh_04_b=='0'||$heh_04_c=='0'||$heh_04_d=='0'||$heh_04_e=='0'||$heh_04_f=='0'||$heh_04_g=='0'){
			//echo "hello";
			header( "location: hc_info.php?serial=15$qstring" );
		}
		else{		
			$hcsql="UPDATE elapsed_time SET end_time='$time' WHERE hhid='$hid'";
			mysql_query($hcsql) or die ("problem timing");
			
			$sql="Delete from track WHERE appid='$resId' and user_id='$user_id' and hid = '$hid'";
			mysql_query($sql) or die ("problem budget_heads");
			header( "location: hc_info.php?serial=16" );
			//echo "last";
		}
		
	}
	else if($qus_no=='hc_15'){
		$time = date('Y-m-d H:i:s',strtotime("+10 hours"));
		$fm1=$_POST['fm1'];
		$fm2=$_POST['fm2'];
				
		$sql="UPDATE household_info set fm1='$fm1', fm2='$fm2' WHERE hid='$hid'";
			mysql_query($sql) or die ("problem rent");
				
		if($fm1==''||$fm2==''){
				header( "location: hc_info.php?serial=16" );
		 }
		 else{
			$hcsql="UPDATE elapsed_time SET end_time='$time' WHERE hhid='$hid'";
			mysql_query($hcsql) or die ("problem timing");
			header( "location: ../index1.php" );
		}
		
	}
?>